package com.ruoyi.invoice.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.invoice.domain.TaxMethods;
import com.ruoyi.invoice.domain.TaxProjects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.invoice.domain.InvoiceProducts;
import com.ruoyi.invoice.service.IInvoiceProductsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 开票商品Controller
 * 
 * @author ruoyi
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/invoice_products")
public class InvoiceProductsController extends BaseController
{
    @Autowired
    private IInvoiceProductsService invoiceProductsService;



    /**
     * 计税下拉框数据
     * @return
     */
    @GetMapping("/getTaxMethodsAll")
    public AjaxResult getTaxProjects()
    {
        List<TaxMethods> list = invoiceProductsService.getTaxMethodsAll();
        return success(list);
    }


    /**
     * 征税下拉框数据
     * @return
     */
    @GetMapping("/getTaxProjectsAll")
    public AjaxResult getTaxProjectsAll()
    {
        List<TaxProjects> list = invoiceProductsService.getTaxProjectsAll();
        return success(list);
    }


    /**
     * 查询开票商品列表
     */
    @RequiresPermissions("invoice:invoice_products:list")
    @GetMapping("/list")
    public TableDataInfo list(InvoiceProducts invoiceProducts)
    {
        startPage();
        List<InvoiceProducts> list = invoiceProductsService.selectInvoiceProductsList(invoiceProducts);
        return getDataTable(list);
    }

    /**
     * 导出开票商品列表
     */
    @RequiresPermissions("invoice:invoice_products:export")
    @Log(title = "开票商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvoiceProducts invoiceProducts)
    {
        List<InvoiceProducts> list = invoiceProductsService.selectInvoiceProductsList(invoiceProducts);
        ExcelUtil<InvoiceProducts> util = new ExcelUtil<InvoiceProducts>(InvoiceProducts.class);
        util.exportExcel(response, list, "开票商品数据");
    }

    /**
     * 获取开票商品详细信息
     */
    @RequiresPermissions("invoice:invoice_products:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(invoiceProductsService.selectInvoiceProductsById(id));
    }

    /**
     * 新增开票商品
     */
    @RequiresPermissions("invoice:invoice_products:add")
    @Log(title = "开票商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated InvoiceProducts invoiceProducts)
    {
        return toAjax(invoiceProductsService.insertInvoiceProducts(invoiceProducts));
    }

    /**
     * 修改开票商品
     */
    @RequiresPermissions("invoice:invoice_products:edit")
    @Log(title = "开票商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InvoiceProducts invoiceProducts)
    {
        return toAjax(invoiceProductsService.updateInvoiceProducts(invoiceProducts));
    }

    /**
     * 删除开票商品
     */
    @RequiresPermissions("invoice:invoice_products:remove")
    @Log(title = "开票商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(invoiceProductsService.deleteInvoiceProductsByIds(ids));
    }



}
